// Generate an 8-bit style avatar based on a seed string
export function generateAvatar(seed: string): string {
  // Create a deterministic color based on the seed
  const getColor = (str: string): string => {
    let hash = 0
    for (let i = 0; i < str.length; i++) {
      hash = str.charCodeAt(i) + ((hash << 5) - hash)
    }

    // Windows 95 color palette
    const colors = [
      "#000080", // navy
      "#008080", // teal
      "#800080", // purple
      "#808000", // olive
      "#800000", // maroon
      "#008000", // green
      "#000000", // black
      "#808080", // gray
    ]

    return colors[Math.abs(hash) % colors.length]
  }

  // Create a simple SVG with a colored background and initial
  const bgColor = getColor(seed)
  const initial = seed.charAt(0).toUpperCase()

  // Create a simple pixel art face
  const svgContent = `
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32" height="32">
      <rect width="32" height="32" fill="${bgColor}" />
      <rect x="8" y="12" width="4" height="4" fill="white" />
      <rect x="20" y="12" width="4" height="4" fill="white" />
      <rect x="12" y="20" width="8" height="2" fill="white" />
    </svg>
  `

  return `data:image/svg+xml;base64,${btoa(svgContent)}`
}
